<div bsModal #createOrEditModal="bs-modal" (onShown)="onShown()" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="createOrEditModal" aria-hidden="true" [config]="{backdrop: 'static'}">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <form *ngIf="active" #userForm="ngForm" novalidate (ngSubmit)="save()" autocomplete="off">
                <div class="modal-header">
                    <h4 class="modal-title">
                        <span *ngIf="user.id">{{l("EditUser")}}: {{user.userName}}</span>
                        <span *ngIf="!user.id">{{l("CreateNewUser")}}</span>
                    </h4>
                    <button type="button" class="close" (click)="close()" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <tabset class="tab-container tabbable-line">
                        <tab heading="{{l('UserInformations')}}" customClass="m-tabs__item">
                            <div class="row">
                                <div class="col-sm-3 text-center margin-bottom-15 margin-top-15">
                                    <img src="{{profilePicture}}" width="128" height="128" class="img-thumbnail img-rounded" />
                                </div>
                                <div class="col-sm-9">
                                    <div class="form-group">
                                        <label>{{l("Name")}}</label>
                                        <input #nameInput class="form-control" type="text" name="Name" [(ngModel)]="user.name" required maxlength="32">
                                    </div>

                                    <div class="form-group">
                                        <label>{{l("Surname")}}</label>
                                        <input type="text" name="Surname" class="form-control" [(ngModel)]="user.surname" required maxlength="32">
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label>{{l("EmailAddress")}}</label>
                                <input type="email" name="EmailAddress" class="form-control" [(ngModel)]="user.emailAddress" required maxlength="256" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$">
                            </div>

                            <div class="form-group">
                                <label>{{l("PhoneNumber")}}</label>
                                <input type="text" name="PhoneNumber" class="form-control" [(ngModel)]="user.phoneNumber" maxlength="24">
                            </div>

                            <div class="form-group">
                                <label>{{l("UserName")}}</label>
                                <input type="text" [disabled]="!canChangeUserName" name="UserName" class="form-control" [(ngModel)]="user.userName" required maxlength="32">
                                <span class="help-block" *ngIf="!canChangeUserName">{{l("CanNotChangeAdminUserName")}}</span>
                            </div>

                            <div class="m-checkbox-list">
                                <label for="EditUser_SetRandomPassword" class="m-checkbox">
                                    <input id="EditUser_SetRandomPassword" type="checkbox" name="SetRandomPassword" [(ngModel)]="setRandomPassword">
                                    {{l("SetRandomPassword")}}
                                    <span></span>
                                </label>
                            </div>
                            <div class="form-group" *ngIf="!setRandomPassword">
                                <div class="right">
                                    <label>{{l("Password")}}</label>
                                    <input type="password" name="Password" #Password="ngModel" id="Password" class="form-control" [(ngModel)]="user.password" [required]="!user.id && !setRandomPassword" maxlength="32"
                                           [requireDigit]="passwordComplexitySetting.requireDigit" [requireLowercase]="passwordComplexitySetting.requireLowercase"
                                           [requireUppercase]="passwordComplexitySetting.requireUppercase" [requireNonAlphanumeric]="passwordComplexitySetting.requireNonAlphanumeric" [requiredLength]="passwordComplexitySetting.requiredLength"
                                           validateEqual="PasswordRepeat" reverse="true">
                                </div>
                            </div>
                            <div [hidden]="setRandomPassword || userForm.form.valid || userForm.form.pristine">
                                <ul class="help-block text-danger" *ngIf="userForm.controls['Password'] && userForm.controls['Password'].errors">
                                    <li [hidden]="!userForm.controls['Password'].errors.requireDigit">{{l("PasswordComplexity_RequireDigit_Hint")}}</li>
                                    <li [hidden]="!userForm.controls['Password'].errors.requireLowercase">{{l("PasswordComplexity_RequireLowercase_Hint")}}</li>
                                    <li [hidden]="!userForm.controls['Password'].errors.requireUppercase">{{l("PasswordComplexity_RequireUppercase_Hint")}}</li>
                                    <li [hidden]="!userForm.controls['Password'].errors.requireNonAlphanumeric">{{l("PasswordComplexity_RequireNonAlphanumeric_Hint")}}</li>
                                    <li [hidden]="!userForm.controls['Password'].errors.requiredLength">{{l("PasswordComplexity_RequiredLength_Hint", passwordComplexitySetting.requiredLength)}}</li>
                                </ul>
                            </div>
                            <div class="form-group" *ngIf="!setRandomPassword">
                                <div class="right">
                                    <label>{{l("PasswordRepeat")}}</label>
                                    <input type="password" name="PasswordRepeat" #PasswordRepeat="ngModel" class="form-control" [(ngModel)]="user.passwordRepeat" [required]="!user.id && !setRandomPassword" maxlength="32"
                                           [requireDigit]="passwordComplexitySetting.requireDigit" [requireLowercase]="passwordComplexitySetting.requireLowercase"
                                           [requireUppercase]="passwordComplexitySetting.requireUppercase" [requireNonAlphanumeric]="passwordComplexitySetting.requireNonAlphanumeric" [requiredLength]="passwordComplexitySetting.requiredLength"
                                           validateEqual="Password" reverse="false">
                                </div>
                            </div>
                            <div [hidden]="setRandomPassword || userForm.form.valid || userForm.form.pristine">
                                <ul class="help-block text-danger" *ngIf="userForm.controls['PasswordRepeat'] && userForm.controls['PasswordRepeat'].errors">
                                    <li [hidden]="!userForm.controls['PasswordRepeat'].errors.requireDigit">{{l("PasswordComplexity_RequireDigit_Hint")}}</li>
                                    <li [hidden]="!userForm.controls['PasswordRepeat'].errors.requireLowercase">{{l("PasswordComplexity_RequireLowercase_Hint")}}</li>
                                    <li [hidden]="!userForm.controls['PasswordRepeat'].errors.requireUppercase">{{l("PasswordComplexity_RequireUppercase_Hint")}}</li>
                                    <li [hidden]="!userForm.controls['PasswordRepeat'].errors.requireNonAlphanumeric">{{l("PasswordComplexity_RequireNonAlphanumeric_Hint")}}</li>
                                    <li [hidden]="!userForm.controls['PasswordRepeat'].errors.requiredLength">{{l("PasswordComplexity_RequiredLength_Hint", passwordComplexitySetting.requiredLength)}}</li>
                                </ul>
                            </div>
                            <div class="m-checkbox-list">
                                <label for="EditUser_ShouldChangePasswordOnNextLogin" class="m-checkbox">
                                    <input id="EditUser_ShouldChangePasswordOnNextLogin" type="checkbox" name="ShouldChangePasswordOnNextLogin" [(ngModel)]="user.shouldChangePasswordOnNextLogin">
                                    {{l("ShouldChangePasswordOnNextLogin")}}
                                    <span></span>
                                </label>

                                <label for="EditUser_SendActivationEmail" class="m-checkbox">
                                    <input id="EditUser_SendActivationEmail" type="checkbox" name="SendActivationEmail" [(ngModel)]="sendActivationEmail">
                                    {{l("SendActivationEmail")}}
                                    <span></span>
                                </label>

                                <label for="EditUser_IsActive" class="m-checkbox">
                                    <input id="EditUser_IsActive" type="checkbox" name="IsActive" [(ngModel)]="user.isActive">
                                    {{l("Active")}}
                                    <span></span>
                                </label>

                                <label *ngIf="isTwoFactorEnabled" for="EditUser_IsTwoFactorEnabled" class="m-checkbox">
                                    <input id="EditUser_IsTwoFactorEnabled" type="checkbox" name="IsTwoFactorEnabled" [(ngModel)]="user.isTwoFactorEnabled">
                                    {{l("IsTwoFactorEnabled")}}
                                    <span></span>
                                </label>

                                <label *ngIf="isLockoutEnabled" for="EditUser_IsLockoutEnabled" class="m-checkbox">
                                    <input id="EditUser_IsLockoutEnabled" type="checkbox" name="IsLockoutEnabled" [(ngModel)]="user.isLockoutEnabled">
                                    {{l("IsLockoutEnabled")}}
                                    <span></span>
                                </label>
                            </div>
                        </tab>
                        <tab heading="{{l('Roles')}}" customClass="m-tabs__item">
                            <ng-template tabHeading>
                                <span class="badge badge-primary">{{getAssignedRoleCount()}}</span>
                            </ng-template>
                            <div class="m-checkbox-list">
                                <label attr.for="EditUser_{{role.roleName}}" class="m-checkbox" *ngFor="let role of roles">
                                    <input id="EditUser_{{role.roleName}}" type="checkbox" name="{{role.roleName}}" [(ngModel)]="role.isAssigned">
                                    {{role.roleDisplayName}}
                                    <span></span>
                                </label>
                            </div>
                        </tab>
                        <tab heading="{{l('OrganizationUnits')}}" customClass="m-tabs__item">
                            <organization-unit-tree #organizationUnitTree></organization-unit-tree>
                        </tab>
                    </tabset>
                </div>
                <div class="modal-footer">
                    <button [disabled]="saving" type="button" class="btn btn-default" (click)="close()">{{l("Cancel")}}</button>
                    <button type="submit" class="btn btn-primary blue" [disabled]="!userForm.form.valid" [buttonBusy]="saving" [busyText]="l('SavingWithThreeDot')"><i class="fa fa-save"></i> <span>{{l("Save")}}</span></button>
                </div>
            </form>
        </div>
    </div>
</div>
